<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	template="/WEB-INF/layouts/standard.xhtml" 
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:rich="http://richfaces.org/rich"
	xmlns:bf="http://www.bssmanager.com/jsf" 
	xmlns:c="http://java.sun.com/jstl/core">


	<ui:define name="formheader">
		<h2>Buildings</h2>
	</ui:define>
	
	<ui:define name="formGlobal">
		<bf:dateSelector controller="#{buildingController}" date="date" ajaxUpdate="false"/>
	</ui:define>

	<ui:define name="content">

		<c:set var="controller" value="${buildingController}" />

		<h:messages errorClass="errors" style="color:#ff1111" />

		<h:form id="#{controller.modelName}">

			<h:panelGrid columns="2">
				<h:outputLabel value="Name:" />
				<c:choose>
					<c:when test="#{controller.editing}">
						<h:outputText value="#{controller.model.name}" />
					</c:when>
					<c:otherwise>
						<h:inputText value="#{controller.model.name}" />
					</c:otherwise>
				</c:choose>

				<h:outputLabel value="Floors:" />

				<h:inputText id="floors" value="#{controller.model.floors}">
				</h:inputText>

			</h:panelGrid>


			<div class="buttonGroup" style="text-align: left;">
				<h:commandButton disabled="#{controller.editing}"
				id="submit" action="#{controller.add}" value="Add" />&#160; <h:commandButton disabled="#{!controller.editing}"
				action="#{controller.update}" value="Update" />&#160; <h:commandButton id="cancel" value="Cancel"
				action="#{controller.cancel}" /></div>

			<rich:dataTable value="${controller.data}" var="aBean" align="left">
				<f:facet name="header">
					<h:panelGrid columns="3">
						<h:outputText value="All #{controller.modelName}s" />
					</h:panelGrid>
				</f:facet>
				<rich:column>
					<f:facet name="header">
						<h:outputText value="Edit" />
					</f:facet>
					<h:commandButton style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
						title="#{controller.editing ? 'Edit already in progress...':'Click to Edit'}" image="/resrc/images/edit1.jpg"
						disabled="#{controller.editing}" action="${controller.select}" />
				</rich:column>
				<rich:column>
					<f:facet name="header">
						<h:outputText value="Delete" />
					</f:facet>
					<h:commandButton
						title="#{controller.editing ? 'Edit is in progress, please complete the editing...':'Click to Delete'}"
						image="/resrc/images/cross1.jpg" style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
						disabled="#{controller.editing}" action="${controller.remove}" immediate="true"
						onclick="if(!showConfirmation('Are you sure to remove #{controller.modelName}: #{aBean.name} ?')) return false;" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Name</f:facet>
					<h:outputText value="#{aBean.name}" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Floors</f:facet>
					<h:outputText value="#{aBean.floors}" />
				</rich:column>
				<c:if test="#{controller.data.rowCount le 0}">
					<f:facet name="footer">
						<h:outputText value="No #{controller.modelName}s available..." />
					</f:facet>
				</c:if>
			</rich:dataTable>
		</h:form>
	</ui:define>
</ui:composition>